package db;

import java.sql.*;

public class DbConnection {
	
	
	
 
    // 数据库的用户名与密码，需要根据自己的设置
    String user = "root";
    String pwd = "";
    String port="3306";
    
    // JDBC 驱动名及数据库 URL
    String driver = "com.mysql.jdbc.Driver";  
    String url = "jdbc:mysql://localhost:"+port+"/RUNOOB";
    
    Connection connection=null;
    
	public DbConnection(){
		
		
		
		try {
			this.connection=DriverManager.getConnection(url, user, pwd);
		}catch(SQLException exception) {
			exception.getMessage();
		}finally{
			System.out.println("数据库连接成功");
		}
	}
	
	public Connection getCon() {
		
		//返回数据库连接
		return this.connection;
	}
	
}
